package com.tanhua.app.controller;

import com.tanhua.app.interceptor.UserHolder;
import com.tanhua.app.service.SoulService;
import com.tanhua.commons.utils.Constants;
import com.tanhua.model.pojo.QuestionnaireResult;
import com.tanhua.model.vo.Answers;
import com.tanhua.model.vo.QuestionnaireVo;
import com.tanhua.model.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")

public class SoulController {
    @Autowired
    private SoulService soulService;

    @GetMapping
    public ResponseEntity testSoul(){
        List<QuestionnaireVo> questionnaireVo = soulService.getQuestionnaireVo();
        return ResponseEntity.ok(questionnaireVo);
    }


    @PostMapping
    public ResponseEntity getSoul(@RequestBody Map<String,List<Answers>> answers){

        List<Answers> answersList = answers.get("answers");

        QuestionnaireResult result = soulService.select(answersList);
        //把结果存起来
        Long id = soulService.save(result);
        return ResponseEntity.ok(id+"");
    }

    @GetMapping("report/{id}")
    public ResponseEntity report(@PathVariable("id") String id){
        int ids = Integer.parseInt(id);
        //查询数据
        ResultVo vo = soulService.selectResult(ids);

        return ResponseEntity.ok(vo);
    }
}
